/**
 * JSP项目组版权所有2009
 * 
 */
package cn.com.change.model;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
//import javax.persistence.JoinColumn;
//import javax.persistence.JoinTable;
//import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * @author <a herf="K.Cancer.2007@gmail.com">Cancer</a>
 *
 */
@Entity
@Table(name = "cha_userProfile")
public class UserProfile extends BaseObject implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Long id;
	private String realname;           //用户中文名
	private Date birthday;
	private String photo;
	private String qqNumber;
	private String msn;
	private String phoneNumber;
	private School school = new School();
	private User user = new User();
//	private HashSet<Interest> interests = new HashSet<Interest>();
//	private HashSet<User> friends = new HashSet<User>();
	
	

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Date getBirthday() {
		return birthday;
	}

	public String getPhoto() {
		return photo;
	}

	public String getQqNumber() {
		return qqNumber;
	}

	public String getMsn() {
		return msn;
	}

	@ManyToOne
	public School getSchool() {
		return school;
	}
	
	public String getRealname() {
		return realname;
	}

	@Column(name = "phone_number")
	public String getPhoneNumber() {
		return phoneNumber;
	}

	@OneToOne
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

//	@OneToMany
//	public HashSet<Interest> getInterests() {
//		return interests;
//	}

//	@ManyToMany
//	@JoinTable(
//			name ="friends_relationship",
//			joinColumns = { @JoinColumn( name = "user_id")},
//			inverseJoinColumns = @JoinColumn( name = "friend_id"))
//	public HashSet<User> getFriends() {
//		return friends;
//	}

	public void setRealname(String realname) {
		this.realname = realname;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}
	
	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public void setPhoto(String photo) {
		this.photo = photo;
	}

	public void setQqNumber(String qqNumber) {
		this.qqNumber = qqNumber;
	}

	public void setMsn(String msn) {
		this.msn = msn;
	}

	public void setSchool(School school) {
		this.school = school;
	}

//	public void setInterests(HashSet<Interest> interests) {
//		this.interests = interests;
//	}

//	public void setFriends(HashSet<User> friends) {
//		this.friends = friends;
//	}

	/* (non-Javadoc)
	 * @see cn.com.change.model.BaseObject#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object o) {
		if(o == null){
			return false;
		}
		if(!(o instanceof UserProfile)){
			return false;
		}
		
		UserProfile profile = (UserProfile) o;
		
		return this.hashCode() == profile.hashCode();
	}

	/* (non-Javadoc)
	 * @see cn.com.change.model.BaseObject#hashCode()
	 */
	@Override
	public int hashCode() {
        int result;
        result = (user != null ? user.hashCode() : 0);
        result = 29 * result + (birthday != null ? birthday.hashCode() : 0);
        result = 29 * result + (qqNumber != null ? qqNumber.hashCode() : 0);
        result = 29 * result + (msn != null ? msn.hashCode() : 0);
        return result;
	}

	/* (non-Javadoc)
	 * @see cn.com.change.model.BaseObject#toString()
	 */
	@Override
	public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
        .append("user", this.user)
        .append("birthday", this.birthday)
        .append("qqNumber", this.qqNumber)
        .append("msn", this.msn).toString();
	}

}
